package com.agan.aganjavaspyder.controller;

import com.agan.aganjavaspyder.crawler.ct_test.BjMobileUtil;
import com.geccocrawler.gecco.downloader.DownloadException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * 爬虫控制器
 * @author agan
 * @ClassName StartChinaTelecomController
 * @Description
 * @Date 2020/10/14 4:39 下午
 **/

@RestController
@RequestMapping("/spider_test")
@Api(value = "StartChinaTelecomController", tags = {"爬虫控制器"})
public class StartChinaTelecomController {


    @GetMapping("/start")
    @ApiOperation(value = "启动爬取")
    public String startSpider(HttpServletResponse response,
                             String url) {
        System.out.println("url:"+url);
        if(url == null){
            try {
                BjMobileUtil.startSpiderByHttp();
            } catch (UnsupportedEncodingException | DownloadException e) {
                e.printStackTrace();
            }
        }
        return "finish";
    }

}
